home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / FTSC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  25KB  |  801 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                 BinkleyTerm FTSC Mail Session Routines                   */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. #define rb_plus "r+b"
  51.  
  52. int FTSC_callback (char *);
  53. int FTSC_time (long);
  54. int FTSC_sendmail (void);
  55. int FTSC_recvmail (int);
  56.  
  57. #define NUM_FLAGS 4
  58.  
  59. void FTSC_sender (int wz)
  60. {
  61.    int j;
  62.    char junkbuff[128];
  63.    long t1;
  64.  
  65.    XON_DISABLE ();
  66.    first_block = 0;
  67.  
  68.    if (!wz)
  69.       {
  70.       first_block = 1;
  71.       status_line (MSG_TXT(M_SEND_FALLBACK));
  72.       who_is_he = 0;
  73.       (void) sprintf (junkbuff, "*%s (%s)",
  74.                          newnodedes.SystemName,
  75.                             Full_Addr_Str (&remote_addr));
  76.       status_line (junkbuff);
  77.       }
  78.  
  79.    Netmail_Session = 1;
  80.  
  81.    (void) FTSC_sendmail ();
  82.    t1 = timerset (4500);
  83.  
  84.    /* See what the receiver would like us to do */
  85.    while ((!timeup (t1)) && CARRIER)
  86.       {
  87.       if ((j = PEEKBYTE ()) >= 0)
  88.          {
  89.          switch (j)
  90.             {
  91.             case TSYNC:
  92.                CLEAR_INBOUND ();
  93.                if (FTSC_recvmail (1))
  94.                   goto get_out;
  95.                t1 = timerset (4500);
  96.                break;
  97.  
  98.             case SYN:
  99.                CLEAR_INBOUND ();
  100.                if (on_our_nickel)
  101.                   (void) SEA_recvreq ();
  102.                else
  103.                   {
  104.                   SENDBYTE (CAN);
  105.                   status_line (MSG_TXT(M_REFUSING_IN_FREQ));
  106.                   }
  107.                t1 = timerset (4500);
  108.                break;
  109.  
  110.             case ENQ:
  111.                CLEAR_INBOUND ();
  112.                SEA_sendreq ();
  113.                goto get_out;
  114.  
  115.             case NAK:
  116.             case 'C':
  117.                CLEAR_INBOUND ();
  118.                SENDBYTE (EOT);
  119.                t1 = timerset (4500);
  120.                break;
  121.  
  122.             default:
  123.                CLEAR_INBOUND ();
  124.                SENDBYTE (SUB);
  125.                break;
  126.             }
  127.          }
  128.       else
  129.          {
  130.          time_release ();
  131.          }
  132.       }
  133.  
  134.    if (!CARRIER)
  135.       {
  136.       status_line (MSG_TXT(M_NO_CARRIER));
  137.       CLEAR_INBOUND ();
  138.       first_block = 0;
  139.       return;
  140.       }
  141.  
  142.    if (timeup (t1))
  143.       {
  144.       (void) FTSC_recvmail (1);
  145.       status_line (MSG_TXT(M_TOO_LONG));
  146.       }
  147.  
  148. get_out:
  149.    first_block = 0;
  150.    t1 = timerset (100);
  151.    while (!timeup (t1))
  152.       time_release ();
  153.    if (!wz)
  154.       status_line (MSG_TXT(M_0001_END));
  155. }
  156.  
  157. int FTSC_receiver (int wz)
  158. {
  159.    char fname[64];
  160.    int havemail, done, np;
  161.    unsigned int i;
  162.    long t1, t2;
  163.    struct stat buf;
  164.    char *HoldName;
  165.    struct FILEINFO dta;
  166.    ADDR tmp;
  167.  
  168.    first_block = 0;
  169.    XON_DISABLE ();
  170.  
  171.    if (!wz)
  172.       {
  173.      first_block = 1;
  174.       status_line (MSG_TXT(M_RECV_FALLBACK));
  175.       who_is_he = 1;
  176.       }
  177.  
  178.    Netmail_Session = 1;
  179.  
  180.    CLEAR_INBOUND ();
  181.  
  182.    /* Save the state of pickup for now */
  183.    done = no_pickup;
  184.    no_pickup = 0;
  185.    if (FTSC_recvmail (0))
  186.       {
  187.       /* Restore the state of pickup */
  188.       no_pickup = done;
  189.       if (!wz)
  190.          status_line (MSG_TXT(M_0001_END));
  191.       first_block = 0;
  192.       return (1);
  193.       }
  194.  
  195.    /* Restore the state of pickup */
  196.    no_pickup = done;
  197.  
  198.    remote_addr = called_addr;
  199.  
  200.    HoldName = HoldAreaNameMunge(&called_addr);
  201.  
  202.    /* Now see if we should send anything back to him */
  203.    (void) sprintf (fname, "%s%s.?UT", HoldName, Hex_Addr_Str (&remote_addr));
  204.    havemail = !dfind (&dta, fname, 0);
  205.  
  206.    if (!havemail)
  207.       {
  208.       (void) sprintf (fname, "%s%s.?LO", HoldName, Hex_Addr_Str (&remote_addr));
  209.       havemail = !dfind (&dta, fname, 0);
  210.       }
  211.  
  212.    if (!havemail)
  213.       {
  214.       for (np = 0; np <= ALIAS_CNT; np++)
  215.          {
  216.          if (alias[np].Net == 0)
  217.             break;
  218.          (void) sprintf (fname, "%s%s.REQ", CURRENT.sc_Inbound, Hex_Addr_Str (&(alias[np])));
  219.          havemail = !dfind (&dta, fname, 0);
  220.          if (havemail)
  221.             break;
  222.          }
  223.       }
  224.  
  225.    if (!havemail)
  226.       {
  227.       status_line (MSG_TXT(M_NOTHING_TO_SEND), Full_Addr_Str (&remote_addr));
  228.       }
  229.    else
  230.       {
  231.       /* OS/2 likes this */
  232.       while (!dfind (&dta, NULL, 1))
  233.          ;
  234.       status_line (MSG_TXT(M_GIVING_MAIL), Full_Addr_Str (&remote_addr));
  235.       /* Send the TSYNC's until we get a C or NAK or CAN back */
  236.       t1 = timerset (3000);                      /* set 30 second timeout */
  237.       done = 0;
  238.       while (!timeup (t1) && CARRIER && !done)   /* till then or CD lost  */
  239.          {
  240.          SENDBYTE (TSYNC);
  241.  
  242.          t2 = timerset (300);
  243.          while (CARRIER && (!timeup (t2)) && !done)
  244.             {
  245.             switch (T